package com.newedu.equipmgr.servlet.system.user;

import com.alibaba.fastjson.JSONObject;
import com.newedu.equipmgr.service.SysUserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(name="UserDeleteServlet", urlPatterns = {"/api/servlet/user/delete"})
public class UserDeleteServlet extends HttpServlet {
    //alt+insert
    // ctrl +o

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doPost(req, resp);
        System.out.println("获取参数id");
        String id = req.getParameter("id");
        System.out.println("已获取"+id);
        if(id!=null){
            SysUserService areaService = new SysUserService();

            JSONObject jsonObject = new JSONObject();
            try{
                boolean delete = areaService.delete(Integer.parseInt(id));
                if(delete){
                    jsonObject.put("status","success");
                    jsonObject.put("message","操作成功");
                }else{
                    jsonObject.put("status","success");
                    jsonObject.put("message","操作成功");
                }
            }
            catch (Exception e){
                e.printStackTrace();
                jsonObject.put("status","fail");
                jsonObject.put("message",e.getMessage());
            }

            resp.setContentType("application/json;charset=utf-8");
            String jsonString = jsonObject.toJSONString();
            System.out.println(jsonString);
            resp.getWriter().println(jsonString);


        }
    }
}

